/*
  Gusimonos help:
  
  Redondos:
    Azul Lila: B
    Morado Rojo: X
    Naranja: O
    Cyan: L
    Verde: G
    
  Triangulares:
    Rojo: S
    Verde: M
    Azul: J
    Amarillo: H
    
  Cuadrados:
    Violeta: P
    Amarillo: K
    Azul: D
    Verde: C
*/
package core
{
  import com.bit101.components.ComboBox;
  import com.bit101.components.FPSMeter;
  import com.bit101.components.Label;
  import com.bit101.components.NumericStepper;
  import com.bit101.components.PushButton;
  import com.bit101.components.Window;
  import core.actions.ActionDisplace;
  import core.actions.ActionFallDown;
  import core.actions.ActionFligFlag;
  import core.actions.ActionJump;
  import core.actions.ActionKick;
  import core.actions.ActionLaser;
  import core.actions.ActionPunch;
  import core.actions.ActionSelectEnemy;
  import core.actions.ActionSlash;
  import core.actions.ActionWalk;
  import core.board.Board;
  import core.board.Position;
  import core.elements.Element;
  import core.elements.ElementTypes;
  import core.elements.MovieClipElement;
  import core.elements.PerspectiveElement;
  import core.elements.specialization.Bimombo;
  import core.elements.specialization.Bomb;
  import core.elements.specialization.Brain;
  import core.elements.specialization.Bubble;
  import core.elements.specialization.EyesInEsse;
  import core.elements.specialization.Gate;
  import core.elements.specialization.Gusimono;
  import core.elements.specialization.Hole;
  import core.elements.specialization.Impeler;
  import core.elements.specialization.MadBat;
  import core.elements.specialization.Projector;
  import core.elements.specialization.Puddle;
  import core.elements.specialization.Shooter;
  import core.elements.specialization.Weebeen;
  import core.elements.TextureElement;
  import core.elements.VirtualElement;
  import core.logic.Input;
  import core.movement.ElementMovement;
  import core.movement.Move;
  import core.sector.Sector;
  import flash.display.DisplayObjectContainer;
  import flash.events.Event;
  import flash.text.*;
  
  
  public class Editor
  {    
    private static const HUGE_NUMBER:int = 99999999;
    
    private static const E_SpeenSpeed:String = "E_SpeenSpeed";
    
    public static const E_CrossTrigger:String = "E_CrossTrigger";        
    public static const E_Column:String = "E_Column";
    public static const E_Block:String = "E_Block";
    public static const E_Hole:String = "E_Hole";
    public static const E_ColumnBreakable:String = "E_ColumnBreakable";
    public static const E_Rock:String = "E_Rock";
    public static const E_Bomb:String = "E_Bomb";
    public static const E_BombSpecial:String = "E_BombSpecial";
    public static const E_BombLoose:String = "E_BombLoose";
    public static const E_BombFatal:String = "E_BombFatal";
    public static const E_Thorns:String = "E_Thorns";
    public static const E_Teleport:String = "E_Teleport";
    public static const E_InertBall:String = "E_InertBall";
    public static const E_BubbleFriendly:String = "E_BubbleFriendly";
    public static const E_BubbleEnemy:String = "E_BubbleEnemy";
    public static const E_TreeTrunk:String = "E_TreeTrunk";
    public static const E_TreeTop:String = "E_TreeTop";
    public static const E_Projector:String = "E_Projector";
    public static const E_Shooter:String = "E_Shooter";
    public static const E_MadBat:String = "E_MadBat";
    public static const E_Impeler:String = "E_Impeler";
    public static const E_Puddle:String = "E_Puddle";
    public static const E_CrazyCoin:String = "E_CrazyCoin";
    public static const E_Brain:String = "E_Brain";
    
    
    private static const E_GusiMono_K:String = "E_GusiMono_K";
    private static const E_Withard:String = "E_Withard";
    private static const E_Bimombo:String = "E_Bimombo";
    
    private static const E_SandBox:String = "E_SandBox";
    
    private static const E_StressTest_1:String = "E_StressTest_1";
    private static const E_StressTest_2:String = "E_StressTest_2";
    private static const E_StressTest_3:String = "E_StressTest_3";
    private static const E_StressTest_4:String = "E_StressTest_4";
    private static const E_StressTest_5:String = "E_StressTest_5";
        
    
    public static const E_Sector_1:String = "E_Sector_1";
    private static const E_GusiMono_S1:String = "E_GusiMono_S1";
    private static const E_SpeenSpeed_S1:String = "E_SpeenSpeed_S1";
    
    public static const E_Sector_2:String = "E_Sector_2";
    private static const E_GusiMono_A_S2:String = "E_GusiMono_A_S2";
    private static const E_GusiMono_B_S2:String = "E_GusiMono_B_S2";
    private static const E_SpeenSpeed_S2:String = "E_SpeenSpeed_S2";
        
    public static const E_Sector_3:String = "E_Sector_3";
    private static const E_GusiMono_S3:String = "E_GusiMono_S3";
    private static const E_GusiMono_S3_B:String = "E_GusiMono_S3_B";
    private static const E_GusiMono_S3_C:String = "E_GusiMono_S3_C";
    private static const E_SpeenSpeed_S3:String = "E_SpeenSpeed_S3";
    
    public static const E_Sector_4:String = "E_Sector_4";
    private static const E_GusiMono_S4_A:String = "E_GusiMono_S4_A";
    private static const E_GusiMono_S4_B:String = "E_GusiMono_S4_B";
    private static const E_SpeenSpeed_S4:String = "E_SpeenSpeed_S4";
    
    public static const E_Sector_5:String = "E_Sector_5";
    private static const E_GusiMono_S5_A:String = "E_GusiMono_S5_A";
    private static const E_GusiMono_S5_B:String = "E_GusiMono_S5_B";
    private static const E_SpeenSpeed_S5:String = "E_SpeenSpeed_S5";
    
    public static const E_Sector_6:String = "E_Sector_6";
    private static const E_GusiMono_S6:String = "E_GusiMono_S6";
    private static const E_SpeenSpeed_S6:String = "E_SpeenSpeed_S6";
    
    public static const E_Sector_7:String = "E_Sector_7";
    private static const E_GusiMono_S7:String = "E_GusiMono_S7";
    private static const E_SpeenSpeed_S7:String = "E_SpeenSpeed_S7";
    
    public static const E_Sector_8:String = "E_Sector_8";
    private static const E_Weebeen_S8_1:String = "E_Weebeen_S8_1";
    private static const E_Weebeen_S8_2:String = "E_Weebeen_S8_2";
    private static const E_Weebeen_S8_3:String = "E_Weebeen_S8_3";
    private static const E_Weebeen_S8_4:String = "E_Weebeen_S8_4";
    private static const E_Weebeen_S8_5:String = "E_Weebeen_S8_5";
    private static const E_SpeenSpeed_S8:String = "E_SpeenSpeed_S8";
    
    public static const E_Sector_9:String = "E_Sector_9";
    private static const E_SpeenSpeed_S9:String = "E_SpeenSpeed_S9";
    
    public static const E_Sector_10:String = "E_Sector_10";
    private static const E_SpeenSpeed_S10:String = "E_SpeenSpeed_S10";
    private static const E_Weebeen_S10A:String = "E_Weebeen_S10A";
    private static const E_Weebeen_S10B:String = "E_Weebeen_S10B";
    private static const E_Weebeen_S10C:String = "E_Weebeen_S10C";
    private static const E_Weebeen_S10D:String = "E_Weebeen_S10D";
    
    public static const E_Sector_11:String = "E_Sector_11";
    private static const E_SpeenSpeed_S11:String = "E_SpeenSpeed_S11";
    private static const E_Trigger_S11:String = "E_Trigger_S11";
    private static const E_Thorns_S11:String = "E_Thorns_S11";
    private static const E_Trigger_Goal_S11:String = "E_Trigger_Goal_S11";
    private static const E_Gate_1_S11:String = "E_Gate_1_S11";
    private static const E_Gate_2_S11:String = "E_Gate_2_S11";
    private static const E_Gate_3_S11:String = "E_Gate_3_S11";    
    
    public static const E_Sector_12:String = "E_Sector_12";
    private static const E_SpeenSpeed_S12:String = "E_SpeenSpeed_S12";
    private static const E_Weebeen_S12A:String = "E_Weebeen_S12A";    
    
    public static const E_Sector_13:String = "E_Sector_13";
    private static const E_SpeenSpeed_S13:String = "E_SpeenSpeed_S13";
    private static const E_Weebeen_S13A:String = "E_Weebeen_S13A";
    
    public static const E_Sector_14:String = "E_Sector_14";
    private static const E_SpeenSpeed_S14:String = "E_SpeenSpeed_S14";
    private static const E_GusiMono_S14_A:String = "E_GusiMono_S14_A";
    private static const E_GusiMono_S14_B:String = "E_GusiMono_S14_B";
    
    public static const E_Sector_15:String = "E_Sector_15";
    private static const E_SpeenSpeed_S15:String = "E_SpeenSpeed_S15";
    private static const E_Gusimono_S15:String = "E_Gusimono_S15";
    private static const E_Weebeen_S15:String = "E_Weebeen_S15";
    private static const E_Bimombo_S15:String = "E_Bimombo_S15";
    private static const E_ColumnBreakable_S15:String = "E_ColumnBreakable_S15";
    private static const E_Trigger_S15:String = "E_Trigger_S15";
    
    public static const E_Sector_16:String = "E_Sector_16";
    private static const E_SpeenSpeed_S16:String = "E_SpeenSpeed_S16";
    private static const E_SpinSlow_S16:String = "E_SpinSlow_S16";
    private static const E_Gusimono_S16_A:String = "E_Gusimono_S16_A";
    private static const E_Gusimono_S16_B:String = "E_Gusimono_S16_B";
    private static const E_Gusimono_S16_C:String = "E_Gusimono_S16_C";
    
    public static const E_Sector_17:String = "E_Sector_17";
    private static const E_SpeenSpeed_S17:String = "E_SpeenSpeed_S17";
    private static const E_EyesInEsse_S17_A:String = "E_EyesInEsse_S17_A";
    private static const E_EyesInEsse_S17_B:String = "E_EyesInEsse_S17_B";
    private static const E_EyesInEsse_S17_C:String = "E_EyesInEsse_S17_C";
    private static const E_EyesInEsse_S17_D:String = "E_EyesInEsse_S17_D";
    private static const E_EyesInEsse_S17_E:String = "E_EyesInEsse_S17_E";
    private static const E_Weebeen_S17_F:String = "E_Weebeen_S17_F";
    private static const E_Weebeen_S17_G:String = "E_Weebeen_S17_G";
    private static const E_Weebeen_S17_H:String = "E_Weebeen_S17_H";
    
    public static const E_Sector_18:String = "E_Sector_18";
    private static const E_SpeenSpeed_S18:String = "E_SpeenSpeed_S18";
    private static const E_GusiMono_S18_A:String = "E_GusiMono_S18_A";
    
    public static const E_Sector_19:String = "E_Sector_19";
    private static const E_SpeenSpeed_S19:String = "E_SpeenSpeed_S19";
    private static const E_EyesInEsse_S19_A:String = "E_EyesInEsse_S19_A";
    private static const E_Weebeen_S19_A:String = "E_Weebeen_S19_A";        
    
    public static const E_Sector_20:String = "E_Sector_20";
    private static const E_SpeenSpeed_S20:String = "E_SpeenSpeed_S20";
    private static const E_EyesInEsse_S20_A:String = "E_EyesInEsse_S20_A";
    private static const E_Chibiru_S20_A:String = "E_Chibiru_S20_A";
    private static const E_Weebeen_S20_A:String = "E_Weebeen_S20_A";
    private static const E_MadBat_S20_A:String = "E_MadBat_S20_A";
    private static const E_Bimombo_S20_A:String = "E_Bimombo_S20_A";
    private static const E_Gate_S20:String = "E_Gate_S20";
    private static const E_DestructorBrain_S20_A:String = "E_DestructorBrain_S20_A";
    
    
    public function Editor(_core:core.Core, debug:Boolean)
    {
      this.myCore = _core;
      this.debug = debug;
      
      var names:Array = new Array(
      E_Sector_11,
      E_SpeenSpeed,
      E_SandBox,
      E_Sector_1,
      E_Sector_2,
      E_Sector_3,
      E_Sector_4,
      E_Sector_5,
      E_Sector_6,
      E_Sector_7,
      E_Sector_8,
      E_Sector_9,
      E_Sector_10,
      E_Sector_11,
      E_Sector_12,
      E_Sector_13,
      E_Sector_14,
      E_Sector_15,
      E_Sector_16,
      E_Sector_17,
      E_Sector_18,
      E_Sector_19,
      E_Sector_20,
      
      E_Weebeen_S10A,
      E_Weebeen_S8_3,
      
      E_StressTest_1,
      E_StressTest_2,
      E_StressTest_3,
      E_StressTest_4,
      E_StressTest_5
      );
      
    
		
		
       if (debug)
       {
         var parent:DisplayObjectContainer = Sector.board.mView[1].parent;
          var window:Window = new Window(parent, 0, 0, "Debug Controls");
          window.draggable = true;
          window.hasMinimizeButton = true;
          window.minimized = true;
          window.setSize(150, 200);
          window.x = 500;
          window.y = 10;
          
          new FPSMeter(window, 10, 10);
          
          comboBox = new ComboBox(window, 10, 30, names[0], names);
          comboBox.selectedItem = names[0];
          comboBox.numVisibleItems = 30;
          
          numericHeight = new NumericStepper(window, 50, 10, onHeightChange);
          numericHeight.maximum = 4;
          numericHeight.minimum = numericHeight.value = 1;
          
          actionLabel = new Label(window, 10, 50);	  
          
          new PushButton(window, 10, 80, "Start Player Turn", onStartPlayerTurn);
          new PushButton(window, 10, 100, "Start Enemy Turn", onStartEnemyTurn);
        
        }
    }
    
    private function onStartPlayerTurn(e:Event):void
    {
      myCore.sector.startPlayerTurn();
    }
    
    private function onStartEnemyTurn(e:Event):void
    {
      myCore.sector.startComputerTurn();
    }
  
    private var myCore:Core;
  private var debug:Boolean;
	private var numericHeight:NumericStepper;
	
	private function onHeightChange(e:Event):void
	{
		height = numericHeight.value;
	}
    
    public function create(name:String, pos:Position):void
    {
      var e:Element;
      var ve:VirtualElement;
      
      var addToBoard:Boolean = true;
      var find:int = name.search("Practice"); 
      if (find != -1) addToBoard = false;
      if (name.search("Sector") != -1) addToBoard = false;
      
      if (addToBoard)
      {
        ve = new VirtualElement;
        ve.position = pos;
      }
      
      
      function CreateSpeenSpeed():MovieClipElement
      {
        ve.name = E_SpeenSpeed;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionJump);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function CreateCrossTrigger():TextureElement
      {
        function OnContact(other:VirtualElement):void
        {
          Sector.board.getElementSelected().enqueuedActions.push(new ActionSelectEnemy);          
        }
        
        ve.jumpingWalk = false;
        ve.name = E_CrossTrigger;
        ve.rebound = false;
        ve.pathFindObstacle = true;
        ve.type = ElementTypes.TYPE_TRIGGER_GOLD;
        ve.initialLife = HUGE_NUMBER;
        ve.alive = false;
        ve.hasVolume = false;
        var t:TextureElement = new TextureElement(ve);
        ve.onContact = ve.onHitted = OnContact;        
        return t;
      }
      
      function CreateHole():PerspectiveElement
      {
        return new Hole(ve);
      }
      
      
      function CreateColumn():PerspectiveElement
      {        
        function OnDie():void
        {
          for (var i:int = 1; i < 4; i++)
          {
            var position:Position = ve.position.clone();
            position.cellY = i;
            Sector.board.getCell(position).element = null;
          }
        }
        
        ve.name = E_Column;
        ve.jumpable = false;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        ve.heavy = true;
        
        for (var i:int = 1; i < 4; i++)
        {
          var position:Position = pos.clone();
          position.cellY = i;
          var columnSegment:VirtualElement = new VirtualElement();
          columnSegment.name = "ColumnSegment";
          columnSegment.initialLife = 100;
          columnSegment.pathFindObstacle = true;
          columnSegment.alive = false;
          columnSegment.type = ElementTypes.TYPE_INVISIBLE;
          columnSegment.position = position;
        }
        
        ve.type = ElementTypes.TYPE_COLUMN;
        
        ve.onDie = OnDie;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        
        return pe;
      }
      
      function CreateColumnBreakable():PerspectiveElement
      {
        function OnDie():void
        {
          for (var i:int = 1; i < 4; i++)
          {
            var position:Position = ve.position.clone();
            position.cellY = i;
            Sector.board.getCell(position).element = null;
          }
        }
        
        ve.name = E_Column;
        ve.jumpable = false;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        ve.heavy = true;
        
        for (var i:int = 1; i < 4; i++)
        {
          var position:Position = pos.clone();
          position.cellY = i;
          var columnSegment:VirtualElement = new VirtualElement();
          columnSegment.name = "ColumnSegment";
          columnSegment.initialLife = 100;
          columnSegment.pathFindObstacle = true;
          columnSegment.alive = false;
          columnSegment.type = ElementTypes.TYPE_INVISIBLE;
          columnSegment.position = position;
        }
        
        ve.type = ElementTypes.TYPE_COLUMN_BREAKABLE;
        
        ve.onDie = OnDie;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        return pe;
      }
      
      function CreateBlock():PerspectiveElement
      {
        ve.name = E_Block;
        ve.jumpable = true;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        ve.rebound = false;
        
        ve.type = ElementTypes.TYPE_BLOCK;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        return pe;
      }
      
      function CreateRock():PerspectiveElement
      {
        ve.name = E_Rock;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        ve.heavy = true;
        
        ve.type = ElementTypes.TYPE_ROCK;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        return pe;
      }
      
      function CreateTreeTop():PerspectiveElement
      {
        ve.name = E_TreeTop;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        ve.heavy = true;
        
        ve.type = ElementTypes.TYPE_TREE_TOP;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        return pe;
      }
      
      function CreateTreeTrunk():PerspectiveElement
      {
        ve.name = E_TreeTrunk;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        ve.heavy = true;
        
        ve.type = ElementTypes.TYPE_TREE_TRUNK;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        return pe;
      }
      
      function CreateBomb():PerspectiveElement
      {
        return new Bomb(ve, ElementTypes.TYPE_BOMB);
      }
      
      function CreateBombSpecial():PerspectiveElement
      {
        return new Bomb(ve, ElementTypes.TYPE_BOMB_SPECIAL);
      }
      
      function CreateBombLoose():PerspectiveElement
      {
        return new Bomb(ve, ElementTypes.TYPE_BOMB_LOOSE);
      }
      
      function CreateBombFatal():PerspectiveElement
      {
        return new Bomb(ve, ElementTypes.TYPE_BOMB_FATAL);
      }
      
      function CreateBimombo():MovieClipElement
      {
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 12;
        return new Bimombo(ve);
      }
      
      function CreateBrain():MovieClipElement
      {
        return new Brain(ve);
      }
      
      function CreateProjector():MovieClipElement
      {
        return new Projector(ve);
      }
      
      function CreateShooter():MovieClipElement
      {
        return new Shooter(ve);
      }
      
      function CreateMadBat():MovieClipElement
      {
        ve.initialLife = ve.currentLife = 5;
        return new MadBat(ve);
      }
      
      function CreateThorns():PerspectiveElement
      {
        
        function OnContact(other:VirtualElement):void
        {
          other.currentLife--;
          if (other.diesOnThornContact && other.currentLife > 0)
            other.currentLife = 0;
        }
        
        function OnHit(other:VirtualElement):void
        {
          OnContact(other);
        }
        
        ve.name = E_Thorns;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        
        ve.onContact = OnContact;
        ve.onHitted = OnHit;
        
        ve.type = ElementTypes.TYPE_THORNS;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        return pe;
      }
      
      function CreateTeleport():PerspectiveElement
      {
        ve.name = E_Thorns;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        
        ve.type = ElementTypes.TYPE_TELEPORT;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        return pe;
      }
      
      function CreateImpeler():PerspectiveElement
      { 
        var pe:PerspectiveElement = new Impeler(ve);
        return pe;
      }
      
      function CreatePuddle():TextureElement
      { 
        var te:TextureElement = new Puddle(ve);
        return te;
      }
      
      function CreateInertBall():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_INERT_BALL;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 0));
        ve.initialLife = ve.currentLife = 1000; // This shouldn't be needed! (not alive elements shouldn't change their currentLife).
        ve.hasVolume = true;
        ve.pathFindObstacle = true;
        ve.alive = false;        
        var me:MovieClipElement = new MovieClipElement(ve);
        ve.name = E_InertBall;
        
        ve.onContact = null;
        ve.onElementTurn = null;
        ve.onEnemyTurn = null;
        ve.onPlayerTurn = null;
        return me;
      }
      
      function CreateCrazyCoin():MovieClipElement
      {
        
        function OnHitted(other:VirtualElement):void
        {
          ve.currentLife--;
          Sector.board.getElementSelected().enqueuedActions.push(new ActionDisplace(ve, ve.position, 3, 2));
        }
        
        ve.type = ElementTypes.TYPE_CRAZY_COIN;
        ve.initialLife = ve.currentLife = 3;
        ve.hasVolume = true;
        ve.pathFindObstacle = true;
        ve.alive = true;      
        ve.hasLifeIndicator = true;  
        var me:MovieClipElement = new MovieClipElement(ve);
        ve.name = E_InertBall;
        
        ve.onHitted = OnHitted;
        
        ve.onContact = null;
        ve.onElementTurn = null;
        ve.onEnemyTurn = null;
        ve.onPlayerTurn = null;
        return me;
      }
      
      function CreateBubbleFriendly():PerspectiveElement
      {
        ve.type = ElementTypes.TYPE_BUBBLE_FRIENDLY;
        ve.alive = false;
        var pe:PerspectiveElement = new Bubble(ve);
        ve.name = E_BubbleFriendly;
        return pe;
      }
      
      function CreateBubbleEnemy():PerspectiveElement
      {
        ve.type = ElementTypes.TYPE_BUBBLE_ENEMY;
        ve.alive = false;
        var pe:PerspectiveElement = new Bubble(ve);
        ve.name = E_BubbleFriendly;
        return pe;
      }
      
      function CreateWithard():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WITHARD;  
        ve.name = E_Withard;
        ve.initialLife = ve.currentLife = 3;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_K():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_K;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));        
        var me:MovieClipElement = new Gusimono(ve);
        return me;
      }
      
      
      /************************************************************************
      * Stress Tests
      * **********************************************************************/
      function StressTest_1():void
      {
        for (var i:int = 0; i < 12; i++)
        for (var j:int = 0; j < 12; j++)        
          create(E_Block, new Position(i,j));
      }
      
      function StressTest_2():void
      {
        var n:int = 0;
        for (var i:int = 0; i < 12; i++)
        {
          for (var j:int = n; j < 12; j+=2)
          {
            create(E_GusiMono_K, new Position(i,j));
          }
          n = n == 0 ? 1 : 0;
        }
      }
      
      function StressTest_3():void
      {
        var n:int = 0;
        for (var i:int = 0; i < 12; i++)
        {
          for (var j:int = n; j < 12; j++)
          {
            create(E_Bomb, new Position(i,j));
            // create(E_Weebeen_S8_1, new Position(i,j));
          }
          // n = n == 0 ? 1 : 0;
        }
      }
      
      function StressTest_4():void
      {
        for (var i:int = 0; i < 12; i++)
        for (var j:int = 0; j < 12; j++)        
          create(E_CrossTrigger, new Position(i,j));
      }
      
      function StressTest_5():void
      {
        for (var h:int = 0; h < 4; h++)
        for (var i:int = 0; i < 12; i++)
        for (var j:int = 0; j < 12; j++)
          Sector.board.getCell(new Position(i,j,h)).mask = h;
      }
      
      function SandBox():void
      {
        /*
        create(E_BubbleFriendly, new Position(8,8));
        create(E_BubbleFriendly, new Position(3,8));
        create(E_Weebeen_S10A, new Position(0,11));
        create(E_Weebeen_S10A, new Position(11,11));
        
        create(E_TreeTrunk, new Position(1,5));
        create(E_TreeTop, new Position(1,5,1));
        create(E_Rock, new Position(2,5));
        create(E_Rock, new Position(3,5));
        create(Editor.E_Weebeen_S10A, new Position(2,4));
        
        
                
        create(E_Block, new Position(5,5));
        create(E_Block, new Position(6,5));
        create(E_Block, new Position(6,5,1));
        
        create(E_Block, new Position(5,3));
        create(E_Rock, new Position(5,3,1));
        create(E_Block, new Position(5,4));
        create(E_Rock, new Position(5,4,1));
        create(E_Block, new Position(6,4));
        create(E_Rock, new Position(6,4,1));
        
        create(E_Block, new Position(7,6));
        create(Editor.E_Weebeen_S10A, new Position(7,5));
        create(Editor.E_CrossTrigger, new Position(7,4));
        
        create(E_GusiMono_S4_A, new Position(10,9));*/
        
        create(E_SpeenSpeed, new Position(0,6));
        create(E_Shooter, new Position(4, 6));                
        create(E_GusiMono_S4_A, new Position(2,5));
      }
      
            
      
      /************************************************************************
      * Sector 1
      * **********************************************************************/
      function Sector_1():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_1);
        
        create(E_CrossTrigger, new Position(1, 2));
        create(E_CrossTrigger, new Position(1, 10));
        create(E_CrossTrigger, new Position(5, 10));
        create(E_CrossTrigger, new Position(10, 6));
        create(E_GusiMono_S1, new Position(2, 8));
        create(E_GusiMono_S1, new Position(4, 4));
        create(E_GusiMono_S1, new Position(8, 3));
        create(E_GusiMono_S1, new Position(8, 7));
        create(E_SpeenSpeed_S1, new Position(5, 0));
      }
      
      function SpeenSpeed_S1():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S1;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 0;
        ve.actionsLeft = 0;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_S1():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        ve.hasLifeIndicator = false;
        ve.currentLife = ve.initialLife = 1000; // Se eliminan con las cruces solo.
        var me:MovieClipElement = new Gusimono(ve);
             
        return me;
      }
      
      
      /************************************************************************
      * Sector 2
      * **********************************************************************/
      function Sector_2():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_2);
        
        create(E_GusiMono_A_S2, new Position(4, 1));
        create(E_GusiMono_A_S2, new Position(5, 3));
        create(E_GusiMono_A_S2, new Position(6, 2));
        create(E_GusiMono_B_S2, new Position(7, 4));
        
        for (var i:int = 0; i < 7; i++)
        {
          create(E_Column, new Position(2, i));
          create(E_Column, new Position(9, i));
        }        
        for (i = 2; i < 10; i++)
          create(E_Column, new Position(i, 7));
            
        create(E_SpeenSpeed_S2, new Position(5, 0));
      }
      
      function SpeenSpeed_S2():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S2;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 1;
        ve.actionsLeft = 1;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_A_S2():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        ve.initialLife = 1;
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new Gusimono(ve);        
        return me;
      }
      
      function GusiMono_B_S2():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        ve.initialLife = 2;
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new Gusimono(ve);        
        return me;
      }
      
      
      /************************************************************************
      * Sector 3
      * **********************************************************************/
      function Sector_3():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_3);
        
        create(E_GusiMono_S3_B, new Position(7, 5));
        create(E_GusiMono_S3_B, new Position(4, 9));
        
        create(E_GusiMono_S3, new Position(1, 0));
        create(E_GusiMono_S3, new Position(7, 0));
        create(E_GusiMono_S3, new Position(10, 1));
        create(E_GusiMono_S3, new Position(2, 2));
        create(E_GusiMono_S3, new Position(6, 2));
        create(E_GusiMono_S3, new Position(5, 3));
        create(E_GusiMono_S3, new Position(8, 3));
        create(E_GusiMono_S3, new Position(0, 4));
        create(E_GusiMono_S3_C, new Position(2, 4)); 
        create(E_GusiMono_S3, new Position(11, 4));        
        create(E_GusiMono_S3, new Position(4, 6));
        create(E_GusiMono_S3_C, new Position(10, 6)); 
        create(E_GusiMono_S3, new Position(2, 7));
        create(E_GusiMono_S3, new Position(6, 8));
        create(E_GusiMono_S3, new Position(11, 8));        
        create(E_GusiMono_S3, new Position(8, 9));
        create(E_GusiMono_S3, new Position(0, 10));
        create(E_GusiMono_S3, new Position(6, 10));
        create(E_GusiMono_S3, new Position(2, 11));
        create(E_GusiMono_S3, new Position(10, 11));
        
        create(E_Rock, new Position(0, 0));
        create(E_Rock, new Position(7, 1));
        create(E_Rock, new Position(3, 3));
        create(E_Rock, new Position(8, 6));
        create(E_Rock, new Position(7, 7));
        create(E_Rock, new Position(2, 8));
                
        create(E_SpeenSpeed_S3, new Position(5, 0));
      }
      
      function SpeenSpeed_S3():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S3;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 1;
        ve.actionsLeft = 1;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_S3():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        ve.currentLife = ve.initialLife = 1;
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new Gusimono(ve);        
        return me;
      }
      
      function GusiMono_S3_B():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_S;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_DIAGONAL, 3, true));
        ve.currentLife = ve.initialLife = 1;
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new Gusimono(ve);        
        return me;
      }
      
      function GusiMono_S3_C():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_P;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_LINEAR, 3, true));
        ve.currentLife = ve.initialLife = 1;
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new Gusimono(ve);        
        return me;
      }
      
      /************************************************************************
      * Sector 4
      * **********************************************************************/
      function Sector_4():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_4);
        
        create(E_CrossTrigger, new Position(4, 4));
        create(E_CrossTrigger, new Position(7, 0));
        create(E_CrossTrigger, new Position(8, 2));
        create(E_CrossTrigger, new Position(11, 0));
        
        create(E_GusiMono_S4_A, new Position(1, 4));
        create(E_GusiMono_S4_A, new Position(3, 2));
        create(E_GusiMono_S4_A, new Position(7, 4));
        
        create(E_GusiMono_S4_B, new Position(0, 9));
        create(E_GusiMono_S4_B, new Position(3, 9));
        create(E_GusiMono_S4_B, new Position(8, 9));
        create(E_GusiMono_S4_B, new Position(11, 9));
        
        create(E_SpeenSpeed_S4, new Position(5, 0));
      }
      
      function SpeenSpeed_S4():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S4;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 1;
        ve.actionsLeft = 1;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_S4_A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 3;
        var me:MovieClipElement = new Gusimono(ve);
        
        return me;
      }
      
      function GusiMono_S4_B():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_O;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 4));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 3;
        
        var me:MovieClipElement = new Gusimono(ve);
        
        return me;
      }
      
      
      
      /************************************************************************
      * Sector 5
      * **********************************************************************/
      function Sector_5():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_5);
        
        create(E_CrossTrigger, new Position(4, 3));
        create(E_CrossTrigger, new Position(5, 11));
        create(E_CrossTrigger, new Position(10, 6));
        
        create(E_GusiMono_S5_A, new Position(2, 3));
        create(E_GusiMono_S5_A, new Position(4, 6));
        create(E_GusiMono_S5_A, new Position(9, 2));
        
        create(E_GusiMono_S5_B, new Position(0, 7));
        create(E_GusiMono_S5_B, new Position(7, 5));
        create(E_GusiMono_S5_B, new Position(11, 11));
        
        create(E_Bomb, new Position(6, 8));
        
        create(E_Rock, new Position(8, 6));
        
        create(E_SpeenSpeed_S5, new Position(5, 0));
      }
      
      function SpeenSpeed_S5():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S5;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 1;
        ve.actionsLeft = 1;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_S5_A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 3;
        var me:MovieClipElement = new Gusimono(ve);
        return me;
      }
      
      function GusiMono_S5_B():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_O;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 4));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 3;
        var me:MovieClipElement = new Gusimono(ve);
        return me;
      }
      
      
      
      
      
      
      
      /************************************************************************
      * Sector 6
      * **********************************************************************/
      function Sector_6():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_6);
        
        create(E_GusiMono_S6, new Position(3, 0));
        create(E_GusiMono_S6, new Position(6, 0));
        create(E_GusiMono_S6, new Position(3, 3));
        create(E_GusiMono_S6, new Position(5, 3));
        create(E_GusiMono_S6, new Position(4, 5));
        
        create(E_Hole, new Position(4, 1));
        create(E_Hole, new Position(5, 2));
        create(E_Hole, new Position(4, 3));
        create(E_Hole, new Position(3, 4));
        create(E_Hole, new Position(7, 6));
        
        create(E_Rock, new Position(6, 5));
        
        for (var i:int = 0; i < 8; i++)
        {
          create(E_Column, new Position(1, i));
          create(E_Column, new Position(10, i));
        }        
        for (i = 1; i <= 10; i++)
          create(E_Column, new Position(i, 8));
        
        create(E_Withard, new Position(9, 10));
        
        create(E_SpeenSpeed_S6, new Position(5, 0));
      }
      
      function SpeenSpeed_S6():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S6;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 1;
        ve.actionsLeft = 1;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionKick);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_S6():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        ve.hasLifeIndicator = false;
        ve.currentLife = ve.initialLife = 3;
        var me:MovieClipElement = new Gusimono(ve);
        
        return me;
      }
      
      
      
      
      
      
      
      /************************************************************************
      * Sector 7
      * **********************************************************************/
      function Sector_7():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_2);
        
        create(E_GusiMono_S7, new Position(0, 11));
        create(E_GusiMono_S7, new Position(3, 2));
        create(E_GusiMono_S7, new Position(6, 2));
        create(E_GusiMono_S7, new Position(10, 1));
        create(E_GusiMono_S7, new Position(10, 9));
        
        create(E_Hole, new Position(1, 11));
        create(E_Hole, new Position(4, 3));
        create(E_Hole, new Position(4, 9));
        create(E_Hole, new Position(5, 5));
        create(E_Hole, new Position(8, 4));
        
        create(E_Thorns, new Position(7, 3));
        create(E_Thorns, new Position(7, 5));
        create(E_Thorns, new Position(9, 3));
        create(E_Thorns, new Position(9, 5));
        
        create(E_Rock, new Position(5, 1));
        create(E_Rock, new Position(8, 3));
        create(E_Rock, new Position(8, 5));
        
        
        create(E_SpeenSpeed_S7, new Position(5, 0));
      }
      
      function SpeenSpeed_S7():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S7;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 2;
        ve.actionsLeft = 2;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_S7():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_O;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 4));
        ve.initialLife = ve.currentLife = 6;
        ve.diesOnHoleContact = true; // Se eliminan cayendo a los hoyales.
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new Gusimono(ve);
        
        return me;
      }
      
      
      
      
      /************************************************************************
      * Sector 8
      * **********************************************************************/
      function Sector_8():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_3);

        create(E_Weebeen_S8_5, new Position(0,0));
        create(E_Weebeen_S8_1, new Position(0,8));
        create(E_Weebeen_S8_3, new Position(0,11));
        create(E_Weebeen_S8_3, new Position(2,9));
        create(E_Weebeen_S8_5, new Position(4,2));
        create(E_Weebeen_S8_3, new Position(5,4));
        create(E_Weebeen_S8_1, new Position(5,6));
        create(E_Weebeen_S8_4, new Position(6,10));
        create(E_Weebeen_S8_1, new Position(7,5));
        create(E_Weebeen_S8_1, new Position(7,8));
        create(E_Weebeen_S8_2, new Position(10,4));
        create(E_Weebeen_S8_5, new Position(11,8));
        create(E_Weebeen_S8_3, new Position(11,11));
        
        create(E_Block, new Position(2,8));
        create(E_Block, new Position(3,0));
        create(E_Block, new Position(3,1));
        create(E_Block, new Position(3,4));
        create(E_Block, new Position(3,5));
        create(E_Block, new Position(3,8));
        create(E_Block, new Position(3,9));
        
        create(E_Block, new Position(5,7));
        create(E_Block, new Position(6,7));
        
        create(E_Block, new Position(8,2));
        create(E_Block, new Position(8,5));
        create(E_Block, new Position(8,6));
        create(E_Block, new Position(8,7));
        create(E_Block, new Position(8,8));
        create(E_Block, new Position(8,11));
        
        create(E_Block, new Position(9,6));
        
        create(E_Rock, new Position(6, 6));
        create(E_Rock, new Position(7, 3));
        
        create(E_InertBall, new Position(4, 0));
        create(E_InertBall, new Position(6, 1));
        create(E_InertBall, new Position(6, 2));
        
        create(E_SpeenSpeed_S8, new Position(5, 0));
      }
      
      function SpeenSpeed_S8():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S8;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 2;
        ve.actionsLeft = 2;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function Weebeen_S8_1():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 1;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      function Weebeen_S8_2():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 2;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      function Weebeen_S8_3():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 3;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      function Weebeen_S8_4():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 4;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      function Weebeen_S8_5():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 5;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      
      
      
      
      /************************************************************************
      * Sector 9
      * **********************************************************************/
      function Sector_9():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_1);
        
        create(E_Block, new Position(0,7));      
        create(E_Block, new Position(2,6));
        create(E_Block, new Position(2,10));
        create(E_Block, new Position(4,9));
        create(E_Block, new Position(6,1));
        create(E_Block, new Position(7,4));
        create(E_Block, new Position(8,0));
        create(E_Block, new Position(9,9));
        create(E_Block, new Position(10,7));
        create(E_Block, new Position(10,10));
        
        for (var i:int = 0; i < 1; i++)
        {
          create(E_Column, new Position(7, 11, i));
          create(E_Column, new Position(8, 11, i));
          create(E_Column, new Position(9, 11, i));
        }
        
        create(E_Rock, new Position(4,5));
        create(E_Rock, new Position(7,7));  
        create(E_Rock, new Position(10,11));
        
        create(E_BombSpecial, new Position(2, 9));  
                
        create(E_InertBall, new Position(1,1));
        create(E_InertBall, new Position(3,4));
        create(E_InertBall, new Position(8,10));
        
        create(E_Teleport, new Position(10,1));
        
        create(E_Trigger_Goal_S11, new Position(11,11));
        
        create(E_SpeenSpeed_S9, new Position(0, 0));
      }
      
      function SpeenSpeed_S9():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S9;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 1;
        ve.actionsLeft = 1;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionFligFlag);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      
      
      
      /************************************************************************
      * Sector 10
      * **********************************************************************/
      function Sector_10():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_2);
        
        /* :'( Con lo que ha costado hacerlas!
        create(E_BubbleEnemy, new Position(3, 7));
        create(E_BubbleEnemy, new Position(6, 2));
        create(E_BubbleEnemy, new Position(8, 9));*/
        
        create(E_BubbleFriendly, new Position(1, 1));
        create(E_BubbleFriendly, new Position(1, 9));
        create(E_BubbleFriendly, new Position(4, 5));
        create(E_BubbleFriendly, new Position(7, 1));
        create(E_BubbleFriendly, new Position(7, 8));
        create(E_BubbleFriendly, new Position(9, 1));
        create(E_BubbleFriendly, new Position(9, 9));
        
        // triangulos rojos
        create(E_Weebeen_S10A, new Position(0, 3));
        create(E_Weebeen_S10A, new Position(0, 7));
        create(E_Weebeen_S10A, new Position(2, 5));
        create(E_Weebeen_S10A, new Position(3, 11));
        
        // triangulos azules
        create(E_Weebeen_S10B, new Position(5, 7));
        create(E_Weebeen_S10B, new Position(6, 5));
        create(E_Weebeen_S10B, new Position(6, 9));
        create(E_Weebeen_S10B, new Position(8, 11));
        
        // cuadrados amarillos
        create(E_Weebeen_S10C, new Position(0, 10));
        create(E_Weebeen_S10C, new Position(2, 2));
        create(E_Weebeen_S10C, new Position(2, 7));
        create(E_Weebeen_S10C, new Position(3, 4));
        
        // cuadrados morados
        create(E_Weebeen_S10D, new Position(8, 4));
        create(E_Weebeen_S10D, new Position(10, 3));
        create(E_Weebeen_S10D, new Position(10, 7));
        create(E_Weebeen_S10D, new Position(10, 9));
                
        create(E_Rock, new Position(4,8));
        create(E_Rock, new Position(8,5));
        
        create(E_BombLoose, new Position(2, 3));
        create(E_BombLoose, new Position(3, 8));
        create(E_BombLoose, new Position(7, 4));
        create(E_BombLoose, new Position(8, 7));
        
        create(E_SpeenSpeed_S10, new Position(5, 0));
      }
      
      function SpeenSpeed_S10():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S10;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function Weebeen_S10A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_S;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_DIAGONAL, 3, true));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 5;
        var me:MovieClipElement = new Gusimono(ve);
        
        return me;
      }
      
      function Weebeen_S10B():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_J;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_DIAGONAL, 2, true));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 5;
        var me:MovieClipElement = new Gusimono(ve);
        
        return me;
      }
      
      function Weebeen_S10C():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_K;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_LINEAR, 2, true));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 5;
        var me:MovieClipElement = new Gusimono(ve);
        
        return me;
      }
      
      function Weebeen_S10D():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_P;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_LINEAR, 3, true));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 5;
        var me:MovieClipElement = new Gusimono(ve);
        
        return me;
      }
      
      
      
      /************************************************************************
      * Sector 11
      * **********************************************************************/
      function Sector_11():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_3);
        
        create(E_InertBall, new Position(0,2));
        create(E_InertBall, new Position(1,5));
        create(E_InertBall, new Position(1,7));
        create(E_InertBall, new Position(2,10));
        create(E_InertBall, new Position(5,9));
        create(E_InertBall, new Position(6,6));
        create(E_InertBall, new Position(11,4));
        
        for (var j:int = 0; j < 1; j++)
        for (var i:int = 0; i <= 9; i++)
          create(E_Column, new Position(3, i, j));
        
        for (j = 0; j < 1; j++)
        for (i = 3; i <= 11; i++)
          create(E_Column, new Position(8, i, j));
          
        create(E_BubbleFriendly, new Position(4, 11));
        create(E_BubbleFriendly, new Position(4, 4));
        
        create(E_Thorns, new Position(4, 8));
        create(E_Thorns, new Position(7, 3));
        
        create(E_Rock, new Position(9,4));
        create(E_Rock, new Position(11,2));  
        create(E_Rock, new Position(11,7));
        
        // Green stuff
        create(E_Trigger_S11, new Position(7,11));
        create(E_Thorns, new Position(6,2)); // TODO Should be green
        
        // Arrival
        create(E_Trigger_Goal_S11, new Position(9,11));
        create(E_Trigger_Goal_S11, new Position(10,11));
        create(E_Trigger_Goal_S11, new Position(11,11));
        
        // Gates
        create(E_Gate_1_S11, new Position(3,10));
        create(E_Gate_1_S11, new Position(3,11));
        
        create(E_Gate_2_S11, new Position(8,0));
        create(E_Gate_2_S11, new Position(8,1));
        create(E_Gate_2_S11, new Position(8,2));
        
        create(E_Gate_3_S11, new Position(9,10));
        create(E_Gate_3_S11, new Position(10,10));
        create(E_Gate_3_S11, new Position(11,10));
        
        create(E_SpeenSpeed_S11, new Position(0, 0));
      }
      
      function SpeenSpeed_S11():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S11;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function Trigger_S11():TextureElement
      {
        function OnContact(other:VirtualElement):void
        {
          Sector.board.eraseElement(Sector.board.getCell(new Position(6,2)).element.element);
        }
        
        ve.jumpingWalk = false;
        ve.name = E_CrossTrigger;
        ve.pathFindObstacle = true;
        ve.type = ElementTypes.TYPE_TRIGGER_GREEN;
        ve.initialLife = HUGE_NUMBER;
        ve.alive = false;
        ve.hasVolume = false;
        var t:TextureElement = new TextureElement(ve);
        ve.onContact = OnContact;
        return t;
      }
      
      function Trigger_Goal_S11():TextureElement
      {
        function OnContact(other:VirtualElement):void
        {
          // TODO: Pasar de sector
        }
        
        ve.jumpingWalk = false;
        ve.name = E_CrossTrigger;
        ve.pathFindObstacle = true;
        ve.type = ElementTypes.TYPE_TRIGGER_BLUE;
        ve.initialLife = HUGE_NUMBER;
        ve.alive = false;
        ve.hasVolume = false;
        ve.rebound = false;
        var t:TextureElement = new TextureElement(ve);
        ve.onContact = OnContact;
        ve.primaryObjective = true;
        return t;
      }
      
      function Gate_1_S11():PerspectiveElement
      {
        return new Gate(ve, 1, new Position(4, 10));
      }
      
      function Gate_2_S11():PerspectiveElement
      {
        return new Gate(ve, 2, new Position(9, 0));
      }
      
      function Gate_3_S11():PerspectiveElement
      {
        return new Gate(ve, 3, new Position(10, 11));
      }

  
      /************************************************************************
      * Sector 12
      * **********************************************************************/
      function Sector_12():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_4);
        
        
        
        create(E_Rock, new Position(2,1));
        create(E_Rock, new Position(2,9));
        create(E_Rock, new Position(3,2));
        create(E_Rock, new Position(3,7));  
        create(E_Rock, new Position(4,3));
        create(E_Rock, new Position(4,4));
        create(E_Rock, new Position(4,6));
        
        create(E_Rock, new Position(7,4));
        create(E_Rock, new Position(7,6));
        create(E_Rock, new Position(8,3));
        create(E_Rock, new Position(8,8));
        create(E_Rock, new Position(9,1));
        create(E_Rock, new Position(9,2));
        create(E_Rock, new Position(9,9));
        
        create(E_Weebeen_S12A, new Position(1, 0));
        create(E_Weebeen_S12A, new Position(1, 5));
        create(E_Weebeen_S12A, new Position(3, 0));
        create(E_Weebeen_S12A, new Position(3, 10));
        create(E_Weebeen_S12A, new Position(4, 2));
        create(E_Weebeen_S12A, new Position(6, 9));
        create(E_Weebeen_S12A, new Position(9, 5));
        create(E_Weebeen_S12A, new Position(10, 1));
        create(E_Weebeen_S12A, new Position(10, 11));
        
        create(E_TreeTrunk, new Position(3,8));
        create(E_TreeTop, new Position(3,8,1));
        
        create(E_TreeTrunk, new Position(7,7));
        create(E_TreeTop, new Position(7,7,1));
        
        create(E_Thorns, new Position(0,11));
        create(E_Thorns, new Position(11,11));
        
        
        create(E_SpeenSpeed_S12, new Position(5, 0));
      }
      
      function SpeenSpeed_S12():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S12;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function Weebeen_S12A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 8;
        ve.diesOnThornContact = true;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      
      
      /************************************************************************
      * Sector 13
      * **********************************************************************/
      function Sector_13():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_5);
        
        create(E_BubbleFriendly, new Position(0,0));
        create(E_BubbleFriendly, new Position(0,6));
        create(E_BubbleFriendly, new Position(1,11));
        create(E_BubbleFriendly, new Position(3,3));
        create(E_BubbleFriendly, new Position(3,9));
        create(E_BubbleFriendly, new Position(6,8));
        create(E_BubbleFriendly, new Position(8,0));
        create(E_BubbleFriendly, new Position(9,11));
        create(E_BubbleFriendly, new Position(11,9));
        
        create(E_Bimombo, new Position(0, 2));
        // create(E_Bimombo, new Position(1, 10));
        create(E_Bimombo, new Position(2, 8));
        // create(E_Bimombo, new Position(8, 2));
        create(E_Bimombo, new Position(9, 1));
        create(E_Bimombo, new Position(9, 9));
        
        create(E_Rock, new Position(2,3));
        create(E_Rock, new Position(6,10));
        
        for (var i:int = 0; i < 1; i++)
        {
          create(E_Column, new Position(4,3,i));
          create(E_Column, new Position(4,4,i));
          create(E_Column, new Position(4,5,i));
          create(E_Column, new Position(4,6,i));
          create(E_Column, new Position(4,7,i));
          create(E_Column, new Position(5,3,i));
          create(E_Column, new Position(5,7,i));
          create(E_Column, new Position(6,3,i));
          create(E_Column, new Position(6,5,i));
          create(E_Column, new Position(6,6,i));
          create(E_Column, new Position(6,7,i));
          create(E_Column, new Position(7,3,i));
          create(E_Column, new Position(7,5,i));
          create(E_Column, new Position(8,3,i));
          create(E_Column, new Position(8,5,i));
          create(E_Column, new Position(9,3,i));
          create(E_Column, new Position(9,5,i));
          create(E_Column, new Position(10,0,i));
          create(E_Column, new Position(10,1,i));
          create(E_Column, new Position(10,2,i));
          create(E_Column, new Position(10,5,i));
          create(E_Column, new Position(10,11,i));
          create(E_Column, new Position(11,5,i));
          create(E_Column, new Position(11,10,i));
          create(E_Column, new Position(11,11,i));
        }
        
        create(E_Weebeen_S13A, new Position(1, 1));
        create(E_Weebeen_S13A, new Position(3, 6));
        create(E_Weebeen_S13A, new Position(11, 6));
        
        create(E_TreeTrunk, new Position(1,4));
        create(E_TreeTop, new Position(1,4,1));
        
        create(E_Bomb, new Position(9,8));
        
        create(E_SpeenSpeed_S13, new Position(5, 0));
      }
      
      function SpeenSpeed_S13():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S13;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function Weebeen_S13A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 5;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      
      /************************************************************************
      * Sector 14
      * **********************************************************************/
      function Sector_14():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_6);
        
        create(E_Rock, new Position(6,10));
        create(E_Rock, new Position(7,9));
        create(E_Rock, new Position(8,9));
        create(E_Rock, new Position(10,7));
        
        create(E_Block, new Position(5,11));
        
        create(E_GusiMono_S14_A, new Position(0,11));
        create(E_GusiMono_S14_A, new Position(3,1));
        create(E_GusiMono_S14_A, new Position(7,4));
        create(E_GusiMono_S14_A, new Position(10,10));
        
        create(E_GusiMono_S14_B, new Position(4,11));
        
        create(E_Thorns, new Position(0,0));
        create(E_Thorns, new Position(0,8));
        create(E_Thorns, new Position(0,9));
        create(E_Thorns, new Position(1,1));
        create(E_Thorns, new Position(1,8));
        create(E_Thorns, new Position(1,9));
        create(E_Thorns, new Position(2,0));
        create(E_Thorns, new Position(2,9));
        create(E_Thorns, new Position(2,10));
        create(E_Thorns, new Position(3,10));
        create(E_Thorns, new Position(3,11));
        
        create(E_Thorns, new Position(4,3));
        create(E_Thorns, new Position(4,4));
        create(E_Thorns, new Position(5,2));
        create(E_Thorns, new Position(5,5));
        create(E_Thorns, new Position(6,2));
        create(E_Thorns, new Position(6,6));
        create(E_Thorns, new Position(7,2));
        create(E_Thorns, new Position(7,6));
        create(E_Thorns, new Position(8,1));
        create(E_Thorns, new Position(8,6));
        create(E_Thorns, new Position(9,2));
        create(E_Thorns, new Position(9,6));
        create(E_Thorns, new Position(10,3));
        create(E_Thorns, new Position(10,4));
        create(E_Thorns, new Position(10,5));
        create(E_Thorns, new Position(10,11));
        create(E_Thorns, new Position(11,0));
        create(E_Thorns, new Position(11,10));
        
        create(E_TreeTrunk, new Position(1,4));
        create(E_TreeTop, new Position(1,4,1));
        
        create(E_TreeTrunk, new Position(5,9));
        create(E_TreeTop, new Position(5,9,1));
        
        create(E_Projector, new Position(4,5));
        
        create(E_SpeenSpeed_S14, new Position(1, 0));
      }
      
      function SpeenSpeed_S14():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S14;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionJump);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_S14_A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_L;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 1));
        ve.currentLife = ve.initialLife = 1;
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new Gusimono(ve);        
        return me;
      }
      
      function GusiMono_S14_B():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_K;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_LINEAR, 2, true));
        ve.currentLife = ve.initialLife = 1;
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new Gusimono(ve);        
        return me;
      }
      
      
      /************************************************************************
      * Sector 15
      * **********************************************************************/
      function Sector_15():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_1);
                
        create(E_Block, new Position(0,0));
        create(E_Block, new Position(0,6));
        create(E_Block, new Position(2,3));
        create(E_Block, new Position(2,4));
        create(E_Block, new Position(2,5));
        create(E_Block, new Position(2,9));
        create(E_Block, new Position(3,3));
        create(E_Block, new Position(3,4));
        create(E_Block, new Position(3,7));
        create(E_Block, new Position(3,8));
        create(E_Block, new Position(3,9));
        create(E_Block, new Position(4,3));
        create(E_Block, new Position(4,4));
        create(E_Block, new Position(4,7));
        create(E_Block, new Position(4,8));
        create(E_Block, new Position(4,9));
        // create(E_Block, new Position(5,11));
        // create(E_Block, new Position(6,0));
        create(E_Block, new Position(9,7));
        create(E_Block, new Position(9,8));
        create(E_Block, new Position(10,7));
        create(E_Block, new Position(11,5));
        
        create(E_ColumnBreakable_S15, new Position(8,7));
        
        for (var i:int = 0; i < 1; i++)
        {
          create(E_Column, new Position(0,1,i));
          create(E_Column, new Position(0,5,i));
          create(E_Column, new Position(0,7,i));
          create(E_Column, new Position(0,11,i));
          create(E_Column, new Position(1,0,i));
          //create(E_Column, new Position(4,11,i));
          //create(E_Column, new Position(5,0,i));
          //create(E_Column, new Position(6,11,i));
          //create(E_Column, new Position(7,0,i));
          create(E_Column, new Position(10,11,i));
          create(E_Column, new Position(11,0,i));
          create(E_Column, new Position(11,4,i));
          create(E_Column, new Position(11,6,i));
          create(E_Column, new Position(11,10,i));
        }
        
        create(E_Thorns, new Position(4,8,1));
        
        create(E_Teleport, new Position(6,7));
        
        create(E_BombLoose, new Position(8,10));
        
        create(E_BubbleFriendly, new Position(4,4,1));
        
        create(E_SpeenSpeed_S15, new Position(5,0));
        
        create(E_Bimombo_S15, new Position(2,6));
        create(E_Bimombo_S15, new Position(8,0));
        
        create(E_MadBat, new Position(3,8,1));
        create(E_MadBat, new Position(6,9,1));
        create(E_MadBat, new Position(9,4,1));
        
        create(E_Weebeen_S15, new Position(1,1));
        create(E_Weebeen_S15, new Position(1,11));
        create(E_Weebeen_S15, new Position(6,3));
        create(E_Weebeen_S15, new Position(11,8));
        
        create(E_Hole, new Position(11,11));
        create(E_Block, new Position(11,11,1));
        create(E_Gusimono_S15, new Position(11,11,2));
        
        create(E_Impeler, new Position(6,7));
      }
      
      function SpeenSpeed_S15():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S15;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.actions.push(new ActionJump);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function ColumnBreakable_S15():PerspectiveElement
      {
        ve.name = E_ColumnBreakable;
        ve.jumpable = true;
        ve.initialLife = 100;
        ve.pathFindObstacle = true;
        ve.alive = false;
        ve.rebound = false;
        ve.diesOnBombExplosion = true;
        ve.onDie = OnDie;
        
        function OnDie():void
        {
          create(E_Trigger_S15, ve.position.clone());
        }
        
        ve.type = ElementTypes.TYPE_COLUMN_BREAKABLE;
        var pe:PerspectiveElement = new PerspectiveElement(ve);
        return pe;
      }
      
      function Trigger_S15():TextureElement
      {
        function OnContact(other:VirtualElement):void
        {
          // Desaparece la piedra bajo el elemento de la esquina y hace que se caiga.
          var block:VirtualElement = Sector.board.getCell(new Position(11,11,1)).element;
          Sector.board.eraseElement(block.element);
          
          var gusi:VirtualElement = Sector.board.getCell(new Position(11,11,2)).element;
          
          Sector.board.getElementSelected().currentAction = new ActionFallDown(gusi, null);          
        }
        
        ve.jumpingWalk = false;
        ve.name = E_CrossTrigger;
        ve.pathFindObstacle = true;
        ve.type = ElementTypes.TYPE_TRIGGER_GOLD;
        ve.initialLife = HUGE_NUMBER;
        ve.alive = false;
        ve.hasVolume = false;
        var t:TextureElement = new TextureElement(ve);
        ve.onContact = ve.onHitted = OnContact;
        return t;
      }
      
      function Gusimono_S15():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.hasLifeIndicator = false;
        ve.diesOnHoleContact = true;
        ve.currentLife = ve.initialLife = 1000; // Se elimina cayendo al hole
        var me:MovieClipElement = new Gusimono(ve);
        ve.primaryObjective = false;
             
        return me;
      }
      
      function Weebeen_S15():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = false; // !
        ve.diesOnThornContact = true;
        ve.initialLife = ve.currentLife = 1000;
        var me:MovieClipElement = new Weebeen(ve);
        ve.primaryObjective = false;
        return me;
      }
      
      function Bimombo_S15():MovieClipElement
      {
        ve.hasLifeIndicator = false;
        ve.initialLife = ve.currentLife = 1000;
        var me:MovieClipElement = new Bimombo(ve);
        ve.primaryObjective = false;
        return me;
      }
      
      
      
      /************************************************************************
      * Sector 16
      * **********************************************************************/
      function Sector_16():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_2);
        
        create(E_Gusimono_S16_A, new Position(0, 6));        
        create(E_Gusimono_S16_A, new Position(2, 0));
        create(E_Gusimono_S16_A, new Position(8, 8));
        create(E_Gusimono_S16_A, new Position(10, 6));
        
        create(E_Gusimono_S16_B, new Position(3, 7));
        create(E_Gusimono_S16_B, new Position(11, 1));
        
        create(E_Gusimono_S16_C, new Position(3, 10));
        create(E_Gusimono_S16_C, new Position(4, 4));
        create(E_Gusimono_S16_C, new Position(9, 3));
        create(E_Gusimono_S16_C, new Position(9, 10));
        
        create(E_Block, new Position(1, 1));
        
        create(E_Column, new Position(1, 8));
        create(E_Column, new Position(5, 10));
        create(E_Column, new Position(6, 10));
        create(E_Column, new Position(8, 4));
        
        create(E_Rock, new Position(1, 3));
        create(E_Rock, new Position(4, 8));
        create(E_Rock, new Position(5, 5));
        create(E_Rock, new Position(8, 10));
        create(E_Rock, new Position(10, 1));
        
        create(E_Puddle, new Position(1, 10));
        create(E_Puddle, new Position(3, 2));
        create(E_Puddle, new Position(7, 2));
        create(E_Puddle, new Position(7, 7));
        create(E_Puddle, new Position(10, 9));
        
        create(E_SpeenSpeed_S16, new Position(5, 0));
        create(E_SpinSlow_S16, new Position(6, 0));
      }
      
      function SpeenSpeed_S16():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S16;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.actions.push(new ActionJump);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function SpinSlow_S16():MovieClipElement
      {
        ve.name = E_SpinSlow_S16;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 2;
        ve.initialLife = 1;
        ve.initialActions = 1;
        ve.actionsLeft = 1;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionLaser);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPIN_SLOW;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function Gusimono_S16_A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_L;
        ve.hasLifeIndicator = true;
        ve.diesOnHoleContact = true;
        ve.currentLife = ve.initialLife = 5; // Se elimina cayendo al hole
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 1));
        var me:MovieClipElement = new Gusimono(ve);
             
        return me;
      }
      
      function Gusimono_S16_B():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_G;
        ve.hasLifeIndicator = true;
        ve.diesOnHoleContact = true;
        ve.currentLife = ve.initialLife = 5; // Se elimina cayendo al hole
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        var me:MovieClipElement = new Gusimono(ve);
             
        return me;
      }
      
      function Gusimono_S16_C():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_B;
        ve.hasLifeIndicator = true;
        ve.diesOnHoleContact = true;
        ve.currentLife = ve.initialLife = 5; // Se elimina cayendo al hole
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        var me:MovieClipElement = new Gusimono(ve);
             
        return me;
      }
      
      
      /************************************************************************
      * Sector 17
      * **********************************************************************/
      function Sector_17():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_3);
        
        create(E_Shooter, new Position(3, 1));
        create(E_Shooter, new Position(6, 10));
        create(E_Shooter, new Position(10, 2));
        
        create(E_EyesInEsse_S17_A, new Position(0, 11));
        create(E_EyesInEsse_S17_B, new Position(11, 11));
        create(E_EyesInEsse_S17_C, new Position(0, 0));
        create(E_EyesInEsse_S17_D, new Position(11, 0));
        create(E_EyesInEsse_S17_E, new Position(5, 5));
        
        create(E_Weebeen_S17_F, new Position(9, 11));
        create(E_Weebeen_S17_G, new Position(1, 2));
        create(E_Weebeen_S17_H, new Position(7, 4));
        
        create(E_Impeler, new Position(1, 9));
        create(E_Impeler, new Position(3, 3));
        create(E_Impeler, new Position(4, 7));
        create(E_Impeler, new Position(6, 7));
        create(E_Impeler, new Position(8, 2));
        create(E_Impeler, new Position(9, 7));
        create(E_Impeler, new Position(10, 5));
        
        create(E_TreeTrunk, new Position(2, 8));
        create(E_TreeTop, new Position(2, 8, 1));
        
        create(E_TreeTrunk, new Position(7, 9));
        create(E_TreeTop, new Position(7, 9, 1));
        
        create(E_InertBall, new Position(8, 8));
        
        create(E_Rock, new Position(5, 6));
        
        create(E_SpeenSpeed_S17, new Position(5, 0));
      }
      
      function SpeenSpeed_S17():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S17;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.actions.push(new ActionJump);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      function EyesInEsse_S17_A():MovieClipElement
      {
        function OnDie():void 
        { for (var i:int = 0; i < Sector.elements.length; i++) { var v:VirtualElement = Sector.elements[i].virtualElement;
          if (v.name == "EyesInEsse_S17_B") { v.currentLife = v.initialLife = 8; v.hasLifeIndicator = true; (v.element as MovieClipElement).reloadClip(); } } 
        }
        
        ve.currentLife = ve.initialLife = 8;
        ve.hasLifeIndicator = true;
        ve.onDie = OnDie;
        var me:MovieClipElement = new EyesInEsse(ve);
        ve.name = "EyesInEsse_S17_A";
        return me;
      }      
      function EyesInEsse_S17_B():MovieClipElement
      {
        function OnDie():void 
        { for (var i:int = 0; i < Sector.elements.length; i++) { var v:VirtualElement = Sector.elements[i].virtualElement;
          if (v.name == "EyesInEsse_S17_C") { v.currentLife = v.initialLife = 8; v.hasLifeIndicator = true; (v.element as MovieClipElement).reloadClip(); } } 
        }
        ve.onDie = OnDie;
        ve.currentLife = ve.initialLife = 1000;
        ve.hasLifeIndicator = false;
        var me:MovieClipElement = new EyesInEsse(ve);
        ve.name = "EyesInEsse_S17_B";
        return me;
      }
      function EyesInEsse_S17_C():MovieClipElement
      {
        function OnDie():void 
        { for (var i:int = 0; i < Sector.elements.length; i++) { var v:VirtualElement = Sector.elements[i].virtualElement;
          if (v.name == "EyesInEsse_S17_D") { v.currentLife = v.initialLife = 8; v.hasLifeIndicator = true; (v.element as MovieClipElement).reloadClip(); } } 
        }
        ve.onDie = OnDie;
        ve.currentLife = ve.initialLife = 1000;
        ve.hasLifeIndicator = false;
        var me:MovieClipElement = new EyesInEsse(ve);
        ve.name = "EyesInEsse_S17_C";
        return me;
      }
      function EyesInEsse_S17_D():MovieClipElement
      {
        function OnDie():void 
        { for (var i:int = 0; i < Sector.elements.length; i++) { var v:VirtualElement = Sector.elements[i].virtualElement;
          if (v.name == "EyesInEsse_S17_E") { v.currentLife = v.initialLife = 8; v.hasLifeIndicator = true; (v.element as MovieClipElement).reloadClip(); } } 
        }
        ve.onDie = OnDie;
        ve.currentLife = ve.initialLife = 1000;
        ve.hasLifeIndicator = false;
        var me:MovieClipElement = new EyesInEsse(ve);
        ve.name = "EyesInEsse_S17_D";
        return me;
      }
      function EyesInEsse_S17_E():MovieClipElement
      {
        function OnDie():void 
        { for (var i:int = 0; i < Sector.elements.length; i++) { var v:VirtualElement = Sector.elements[i].virtualElement;
          if (v.name == "Weebeen_S17_F") { v.currentLife = v.initialLife = 1; v.hasLifeIndicator = true; (v.element as MovieClipElement).reloadClip(); } } 
        }
        ve.onDie = OnDie;
        ve.currentLife = ve.initialLife = 1000;
        ve.hasLifeIndicator = false;
        var me:MovieClipElement = new EyesInEsse(ve);
        ve.name = "EyesInEsse_S17_E";
        return me;
      }
      function Weebeen_S17_F():MovieClipElement
      {
        function OnDie():void 
        { for (var i:int = 0; i < Sector.elements.length; i++) { var v:VirtualElement = Sector.elements[i].virtualElement;
          if (v.name == "Weebeen_S17_G") { v.currentLife = v.initialLife = 1; v.hasLifeIndicator = true; (v.element as MovieClipElement).reloadClip(); } } 
        }
        ve.onDie = OnDie;
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = false;
        ve.initialLife = ve.currentLife = 1000;
        var me:MovieClipElement = new Weebeen(ve);
        ve.name = "Weebeen_S17_F";
        return me;
      }
      function Weebeen_S17_G():MovieClipElement
      {
        function OnDie():void 
        { for (var i:int = 0; i < Sector.elements.length; i++) { var v:VirtualElement = Sector.elements[i].virtualElement;
          if (v.name == "Weebeen_S17_H") { v.currentLife = v.initialLife = 1; v.hasLifeIndicator = true; (v.element as MovieClipElement).reloadClip(); } } 
        }
        ve.onDie = OnDie;
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = false;
        ve.initialLife = ve.currentLife = 1000;
        var me:MovieClipElement = new Weebeen(ve);
        ve.name = "Weebeen_S17_G";
        return me;
      }
      function Weebeen_S17_H():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = false;
        ve.initialLife = ve.currentLife = 1000;
        var me:MovieClipElement = new Weebeen(ve);
        ve.name = "Weebeen_S17_H";
        return me;
      }
      
      
      
      /************************************************************************
      * Sector 18
      * **********************************************************************/
      function Sector_18():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_4);
        
        create(E_GusiMono_S18_A, new Position(0, 11));
        create(E_GusiMono_S18_A, new Position(3, 0));
        create(E_GusiMono_S18_A, new Position(5, 4));
        create(E_GusiMono_S18_A, new Position(9, 8));
        create(E_GusiMono_S18_A, new Position(11, 0));
        
        create(E_SpeenSpeed_S18, new Position(5, 0));
      }
      
      function SpeenSpeed_S18():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S18;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionSlash);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function GusiMono_S18_A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_O;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 4));
        ve.hasLifeIndicator = true;
        ve.currentLife = ve.initialLife = 2;
        var me:MovieClipElement = new Gusimono(ve);
             
        return me;
      }
      
      
      /************************************************************************
      * Sector 19
      * **********************************************************************/
      function Sector_19():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_5);
        
        create(E_CrossTrigger, new Position(0, 0));
        create(E_CrossTrigger, new Position(0, 11));
        create(E_CrossTrigger, new Position(3, 4));
        create(E_CrossTrigger, new Position(3, 7));
        create(E_CrossTrigger, new Position(4, 3));
        create(E_CrossTrigger, new Position(4, 8));
        create(E_CrossTrigger, new Position(7, 3));
        create(E_CrossTrigger, new Position(7, 8));
        create(E_CrossTrigger, new Position(8, 4));
        create(E_CrossTrigger, new Position(8, 7));
        create(E_CrossTrigger, new Position(11, 0));
        create(E_CrossTrigger, new Position(11, 11));
        
        create(E_Column, new Position(1, 1));
        create(E_Column, new Position(1, 10));
        create(E_Column, new Position(3, 3));
        create(E_Column, new Position(3, 8));
        create(E_Column, new Position(4, 4));
        create(E_Column, new Position(4, 5));
        create(E_Column, new Position(4, 6));
        create(E_Column, new Position(4, 7));
        create(E_Column, new Position(5, 4));
        create(E_Column, new Position(5, 7));
        create(E_Column, new Position(6, 4));
        create(E_Column, new Position(6, 7));
        create(E_Column, new Position(7, 4));
        create(E_Column, new Position(7, 5));
        create(E_Column, new Position(7, 6));
        create(E_Column, new Position(7, 7));
        create(E_Column, new Position(8, 3));
        create(E_Column, new Position(8, 8));
        create(E_Column, new Position(10, 1));
        create(E_Column, new Position(10, 10));
        
        create(E_EyesInEsse_S19_A, new Position(1, 4));
        create(E_EyesInEsse_S19_A, new Position(1, 8));
        create(E_EyesInEsse_S19_A, new Position(2, 0));
        create(E_EyesInEsse_S19_A, new Position(3, 10));
        create(E_EyesInEsse_S19_A, new Position(7, 11));
        create(E_EyesInEsse_S19_A, new Position(8, 1));
        create(E_EyesInEsse_S19_A, new Position(10, 7));        
        create(E_EyesInEsse_S19_A, new Position(11, 2));
        
        create(E_Weebeen_S19_A, new Position(0, 6));
        create(E_Weebeen_S19_A, new Position(4, 2));
        create(E_Weebeen_S19_A, new Position(5, 11));
        create(E_Weebeen_S19_A, new Position(9, 5));
        
        create(E_SpeenSpeed_S19, new Position(5, 0));
      }
      
      function SpeenSpeed_S19():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S19;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.actions.push(new ActionSlash);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function EyesInEsse_S19_A():MovieClipElement
      {
        ve.currentLife = ve.initialLife = 10000;
        ve.hasLifeIndicator = false;
        var me:MovieClipElement = new EyesInEsse(ve);
        return me;
      }
      
      function Weebeen_S19_A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = false;
        ve.initialLife = ve.currentLife = 1000;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      
      
      
      /************************************************************************
      * Sector 20
      * **********************************************************************/
      function Sector_20():void
      {
        Sector.board.setBoardType(Board.BOARD_TYPE_6);
        
        create(E_Chibiru_S20_A, new Position(0, 5));
        create(E_Chibiru_S20_A, new Position(0, 10));
        
        create(E_BubbleFriendly, new Position(1, 3));
        
        create(E_EyesInEsse_S20_A, new Position(1, 8));
        
        create(E_CrazyCoin, new Position(2, 5));
        
        create(E_Shooter, new Position(2, 8));
        
        create(E_Bimombo_S20_A, new Position(2, 0));
        create(E_Bimombo_S20_A, new Position(3, 10));
        
        create(E_Weebeen_S20_A, new Position(4, 3));
        create(E_Weebeen_S20_A, new Position(9, 9, 1));
        
        create(E_MadBat_S20_A, new Position(4, 6, 1));
        create(E_MadBat_S20_A, new Position(8, 5, 1));
        
        create(E_Column, new Position(4, 8));
        create(E_Column, new Position(6, 0));
        create(E_Column, new Position(6, 1));
        create(E_Column, new Position(6, 2));
        create(E_Column, new Position(6, 3));
        create(E_Column, new Position(6, 4));
        create(E_Column, new Position(6, 5));
        create(E_Column, new Position(6, 6));
        create(E_Column, new Position(6, 7));
        create(E_Column, new Position(7, 8));
        create(E_Column, new Position(9, 3));
        create(E_Column, new Position(10, 3));
        create(E_Column, new Position(11, 3));
        
        create(E_Rock, new Position(6, 9));
        
        create(E_Gate_S20, new Position(7, 3));
        create(E_Gate_S20, new Position(8, 3));
        
        create(E_TreeTrunk, new Position(7, 10));
        create(E_TreeTop, new Position(7, 10, 1));
        
        create(E_Block, new Position(7, 11));
        create(E_Block, new Position(9, 5));
        create(E_Block, new Position(9, 9));
        create(E_Block, new Position(10, 9));
        create(E_Block, new Position(11, 7));
        
        create(E_Hole, new Position(7, 11, 1));
        
        create(E_Thorns, new Position(8, 1));
        create(E_Thorns, new Position(10, 1));
        
        
        
        create(E_InertBall, new Position(9, 6));
        create(E_InertBall, new Position(10, 7));
        create(E_InertBall, new Position(9, 8));
        
        create(E_Projector, new Position(11, 7, 1));
        
        create(E_SpeenSpeed_S20, new Position(5, 0));
      }
      
      function SpeenSpeed_S20():MovieClipElement
      {
        ve.name = E_SpeenSpeed_S20;
        ve.selectable = true;
        ve.jumpingWalk = false;
        ve.movementRange = 4;
        ve.initialLife = 4;
        ve.initialActions = 3;
        ve.actionsLeft = 3;
        ve.pathFindObstacle = true;
        
        ve.actions.push(new ActionWalk);
        ve.actions.push(new ActionPunch);
        ve.actions.push(new ActionKick);
        ve.actions.push(new ActionFligFlag);
        ve.actions.push(new ActionSlash);
        ve.currentAction = ve.actions[0];
        
        ve.type = ElementTypes.TYPE_SPEEN_SPEED;
        var me:MovieClipElement = new MovieClipElement(ve);
        return me;
      }
      
      function EyesInEsse_S20_A():MovieClipElement
      {
        ve.currentLife = ve.initialLife = 10;
        ve.hasLifeIndicator = true;
        var me:MovieClipElement = new EyesInEsse(ve);
        return me;
      }
      
      function Weebeen_S20_A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_WEEBEEN;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 3));
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 10;
        var me:MovieClipElement = new Weebeen(ve);
        return me;
      }
      
      function Chibiru_S20_A():MovieClipElement
      {
        ve.type = ElementTypes.TYPE_GUSIMONO_K;
        ve.movement = new ElementMovement(ElementMovement.TREND_ACERCAMIENTO);
        ve.movement.addMoveType(new Move(Move.TYPE_FREE, 2));
        ve.currentLife = ve.initialLife = 5;    
        var me:MovieClipElement = new Gusimono(ve);
        ve.onContact = function(other:VirtualElement):void{}; // Chibiru is innocuous
        return me;
      }
      function MadBat_S20_A():MovieClipElement
      {
        ve.initialLife = ve.currentLife = 10;
        return new MadBat(ve);
      }      
      function Bimombo_S20_A():MovieClipElement
      {
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 10;
        var me:MovieClipElement = new Bimombo(ve);
        return me;
      }
      function Gate_S20():PerspectiveElement
      {
        var pe:PerspectiveElement = new Gate(ve, 1, new Position(7, 2));
        (pe as Gate).triggerCallback = onGateTriggered;
        
        function onGateTriggered():void
        {
          create(E_DestructorBrain_S20_A, new Position(9, 1));
        }
        
        return pe;
      }
      function DestructorBrain_S20_A():MovieClipElement
      {
        ve.hasLifeIndicator = true;
        ve.initialLife = ve.currentLife = 18;
        var me:MovieClipElement = new Brain(ve);
        return me;
      }
      
      
      
      /************************************************************************
      * Sectors end
      * **********************************************************************/
      
      switch (name)
      {
        case E_SpeenSpeed: e = CreateSpeenSpeed(); break;
        case E_CrossTrigger: e = CreateCrossTrigger(); break;
        case E_Hole: e = CreateHole(); break;
        case E_GusiMono_K: e = GusiMono_K(); break;
        case E_Column: e = CreateColumn(); break;
        case E_Block: e = CreateBlock(); break;
        case E_ColumnBreakable: e = CreateColumnBreakable(); break;
        case E_Rock: e = CreateRock(); break;
        case E_Bomb: e = CreateBomb(); break;
        case E_BombSpecial: e = CreateBombSpecial(); break;
        case E_BombLoose: e = CreateBombLoose(); break;
        case E_BombFatal: e = CreateBombFatal(); break;
        case E_Thorns: e = CreateThorns(); break;
        case E_Teleport: e = CreateTeleport(); break;
        case E_InertBall: e = CreateInertBall(); break;
        case E_BubbleFriendly: e = CreateBubbleFriendly(); break;
        case E_BubbleEnemy: e = CreateBubbleEnemy(); break;
        case E_Withard: e = CreateWithard(); break;
        case E_TreeTrunk: e = CreateTreeTrunk(); break;
        case E_TreeTop: e = CreateTreeTop(); break;
        case E_Bimombo: e = CreateBimombo(); break;
        case E_Projector: e = CreateProjector(); break;
        case E_Shooter: e = CreateShooter(); break;
        case E_MadBat: e = CreateMadBat(); break;
        case E_Impeler: e = CreateImpeler(); break;
        case E_Puddle: e = CreatePuddle(); break;
        case E_CrazyCoin: e = CreateCrazyCoin(); break;
        case E_Brain: e = CreateBrain(); break;
        
        
        
        // Sector 1
        case E_Sector_1: Sector_1(); break;
        case E_GusiMono_S1: e = GusiMono_S1(); break;
        case E_SpeenSpeed_S1: e = SpeenSpeed_S1(); break;
        
        // Sector 2        
        case E_Sector_2: Sector_2(); break;
        case E_GusiMono_A_S2: e = GusiMono_A_S2(); break;
        case E_GusiMono_B_S2: e = GusiMono_B_S2(); break;
        case E_SpeenSpeed_S2: e = SpeenSpeed_S2(); break;
        
        // Sector 3
        case E_Sector_3: Sector_3(); break;
        case E_GusiMono_S3: e = GusiMono_S3(); break;
        case E_GusiMono_S3_B: e = GusiMono_S3_B(); break;
        case E_GusiMono_S3_C: e = GusiMono_S3_C(); break;
        case E_SpeenSpeed_S3: e = SpeenSpeed_S3(); break;
        
        
        // Sector 4
        case E_Sector_4: Sector_4(); break;
        case E_GusiMono_S4_A: e = GusiMono_S4_A(); break;
        case E_GusiMono_S4_B: e = GusiMono_S4_B(); break;
        case E_SpeenSpeed_S4: e = SpeenSpeed_S4(); break;
        
        // Sector 5
        case E_Sector_5: Sector_5(); break;
        case E_GusiMono_S5_A: e = GusiMono_S5_A(); break;
        case E_GusiMono_S5_B: e = GusiMono_S5_B(); break;
        case E_SpeenSpeed_S5: e = SpeenSpeed_S5(); break;
        
        // Sector 6
        case E_Sector_6: Sector_6(); break;
        case E_GusiMono_S6: e = GusiMono_S6(); break;
        case E_SpeenSpeed_S6: e = SpeenSpeed_S6(); break;
        
        // Sector 7
        case E_Sector_7: Sector_7(); break;
        case E_GusiMono_S7: e = GusiMono_S7(); break;
        case E_SpeenSpeed_S7: e = SpeenSpeed_S7(); break;
        
        // Sector 8
        case E_Sector_8: Sector_8(); break;
        case E_Weebeen_S8_1: e = Weebeen_S8_1(); break;
        case E_Weebeen_S8_2: e = Weebeen_S8_2(); break;
        case E_Weebeen_S8_3: e = Weebeen_S8_3(); break;
        case E_Weebeen_S8_4: e = Weebeen_S8_4(); break;
        case E_Weebeen_S8_5: e = Weebeen_S8_5(); break;
        case E_SpeenSpeed_S8: e = SpeenSpeed_S8(); break;
        
        // Sector 9
        case E_Sector_9: Sector_9(); break;
        case E_SpeenSpeed_S9: e = SpeenSpeed_S9(); break;
        
        // Sector 10
        case E_Sector_10: Sector_10(); break;
        case E_SpeenSpeed_S10: e = SpeenSpeed_S10(); break;
        case E_Weebeen_S10A: e = Weebeen_S10A(); break;
        case E_Weebeen_S10B: e = Weebeen_S10B(); break;
        case E_Weebeen_S10C: e = Weebeen_S10C(); break;
        case E_Weebeen_S10D: e = Weebeen_S10D(); break;
        
        // Sector 11
        case E_Sector_11: Sector_11(); break;
        case E_SpeenSpeed_S11: e = SpeenSpeed_S11(); break;
        case E_Trigger_S11: e = Trigger_S11(); break;
        case E_Trigger_Goal_S11: e = Trigger_Goal_S11(); break;
        case E_Gate_1_S11: e = Gate_1_S11(); break;
        case E_Gate_2_S11: e = Gate_2_S11(); break;
        case E_Gate_3_S11: e = Gate_3_S11(); break;
        
        // Sector 12
        case E_Sector_12: Sector_12(); break;
        case E_SpeenSpeed_S12:  e = SpeenSpeed_S12(); break;
        case E_Weebeen_S12A: e = Weebeen_S12A(); break;
        
        // Sector 13
        case E_Sector_13: Sector_13(); break;
        case E_SpeenSpeed_S13:  e = SpeenSpeed_S13(); break;
        case E_Weebeen_S13A: e = Weebeen_S13A(); break;
        
        // Sector 14
        case E_Sector_14: Sector_14(); break;
        case E_SpeenSpeed_S14:  e = SpeenSpeed_S14(); break;
        case E_GusiMono_S14_A: e = GusiMono_S14_A(); break;
        case E_GusiMono_S14_B: e = GusiMono_S14_B(); break;
        
        // Sector 15
        case E_Sector_15: Sector_15(); break;
        case E_SpeenSpeed_S15:  e = SpeenSpeed_S15(); break;
        case E_Gusimono_S15: e = Gusimono_S15(); break;
        case E_Weebeen_S15: e = Weebeen_S15(); break;
        case E_Bimombo_S15: e = Bimombo_S15(); break;
        case E_ColumnBreakable_S15: e = ColumnBreakable_S15(); break;
        case E_Trigger_S15: e = Trigger_S15(); break;
        
        // Sector 16
        case E_Sector_16: Sector_16(); break;
        case E_SpeenSpeed_S16: e = SpeenSpeed_S16(); break;
        case E_SpinSlow_S16: e = SpinSlow_S16(); break;
        case E_Gusimono_S16_A: e = Gusimono_S16_A(); break;
        case E_Gusimono_S16_B: e = Gusimono_S16_B(); break;
        case E_Gusimono_S16_C: e = Gusimono_S16_C(); break;
        
        // Sector 17
        case E_Sector_17: Sector_17(); break;
        case E_SpeenSpeed_S17: e = SpeenSpeed_S17(); break;
        case E_EyesInEsse_S17_A: e = EyesInEsse_S17_A(); break;
        case E_EyesInEsse_S17_B: e = EyesInEsse_S17_B(); break;
        case E_EyesInEsse_S17_C: e = EyesInEsse_S17_C(); break;
        case E_EyesInEsse_S17_D: e = EyesInEsse_S17_D(); break;
        case E_EyesInEsse_S17_E: e = EyesInEsse_S17_E(); break;
        case E_Weebeen_S17_F: e = Weebeen_S17_F(); break;
        case E_Weebeen_S17_G: e = Weebeen_S17_G(); break;
        case E_Weebeen_S17_H: e = Weebeen_S17_H(); break;
        
        // Sector 18
        case E_Sector_18: Sector_18(); break;
        case E_SpeenSpeed_S18: e = SpeenSpeed_S18(); break;
        case E_GusiMono_S18_A: e = GusiMono_S18_A(); break;
        
        // Sector 19
        case E_Sector_19: Sector_19(); break;
        case E_SpeenSpeed_S19: e = SpeenSpeed_S19(); break;
        case E_EyesInEsse_S19_A: e = EyesInEsse_S19_A(); break;
        case E_Weebeen_S19_A: e = Weebeen_S19_A(); break;
        
        // Sector 20
        case E_Sector_20: Sector_20(); break;
        case E_SpeenSpeed_S20: e = SpeenSpeed_S20(); break;
        case E_EyesInEsse_S20_A: e = EyesInEsse_S20_A(); break;
        case E_Chibiru_S20_A: e = Chibiru_S20_A(); break;
        case E_Weebeen_S20_A: e = Weebeen_S20_A(); break;
        case E_MadBat_S20_A: e = MadBat_S20_A(); break;
        case E_Bimombo_S20_A: e = Bimombo_S20_A(); break;
        case E_Gate_S20: e = Gate_S20(); break;
        case E_DestructorBrain_S20_A: e = DestructorBrain_S20_A(); break;
                
        
        // Stress tests
        case E_StressTest_1: StressTest_1(); break;
        case E_StressTest_2: StressTest_2(); break;
        case E_StressTest_3: StressTest_3(); break;
        case E_StressTest_4: StressTest_4(); break;
        case E_StressTest_5: StressTest_5(); break;
        
        // Sand Box
        case E_SandBox: SandBox(); break;
        
      };
      
      if (ve && ve.type == null)
      {
        ve.position = null; // Por si había pillado una posición en el tablero, lo quitamos.
      }
      
      if (e)
      {
        ve = e.virtualElement;
        ve.currentLife = ve.initialLife;
        ve.movesLeft = ve.movementRange;
        
        // Random initial direction
        var r:Number = Math.random()*3;
        ve.lookDir.x = r < 1 ? -1 : r < 2 ? 0 : 1;
        r = Math.random()*3;
        ve.lookDir.y = r < 1 ? -1 : r < 2 ? 0 : 1;
                
        Sector.board.insertElement(e);
      }
      
      if (ve && ve.selectable && Sector.board.getElementSelected() == null)
      {
        Sector.board.setElementSelected(ve);
      }
    }
    
    private function destroy():void
    {
      var p:Position = Input.rayCast(0);
      if (!p) return;
      p.cellY = height-1;
      var e:VirtualElement = Sector.board.getCell(p).element;
      if (e)
      {
        Sector.board.eraseElement(e.element);
      }
    }
    
    public function clear():void
    {
      for (var i:int = 0; i < Sector.elements.length; i++)
      {
        Sector.board.eraseElement(Sector.elements[i--]);
      }
    }
        
    public function update():void
    {
      if (!debug) return;
      
      if (Input.isDown(Input.KEY_INSERT)  || Input.isDown(Input.KEY_NUMPAD_ADD))
      {
        var p:Position = Input.rayCast(0);
        if (p)
        {
          p.cellY = height-1;
          create((comboBox.selectedItem) as String, p);
        }
      }
      if (Input.isDown(Input.KEY_DELETE)  || Input.isDown(Input.KEY_NUMPAD_SUB)) destroy();
      if (Input.isDown(Input.KEY_HOME) || Input.isDown(Input.KEY_NUMPAD5))
      {
        clear();
      }
	  
      if (Sector.board.getElementSelected() && Sector.board.getElementSelected().currentAction)
      {
		  actionLabel.text = "" + Sector.board.getElementSelected().currentAction;
      }
    }
    
    private var comboBox:ComboBox;
    private var height:int = 1;
	private var actionLabel:Label;

  }
  
}